<?php

    function mydate($date)
    {
       $day=substr($date,8,2);
       $mymonth = array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
       $month=substr($date,5,2);
       $year=substr($date,2,2);
       $temp=$day.' '.$mymonth[$month-1].' '.$year;
       return $temp;
    }

    if(!empty($articles))
    {
        
        echo "<label id='left'>   <b>ID</b>     </label>";   
        echo "<label id='center'> <b>Title</b>   </label>";
        echo "<label id='left'>   <b>Date</b>   </label>";
        echo "<label id='left'>   <b>Status</b> </label>";
        echo "<label id='action2'><b>Action</b> </label>";
        echo "<br><hr width='640px'>";        
        foreach($articles as $data)
        {
            echo "<label id='left'>".$data['articles']['id']."</label>";
            echo "<label id='center'>".$data['articles']['title']."</label>";
            echo "<label id='left'>".mydate($data['articles']['created'])."</label>";
            echo "<label id='left'>";
            if($data['articles']['status']==1)
            { 
                echo " Published "; 
                echo "</label><label id='action2'>";
                echo $ajax->link('[ Store ]',
                                    array('controller'=>'articles','action'=>'cancel_admin',$data['articles']['id']),
                                    array('update'=>'result','class'=>'sky','complete'=>"document.getElementById('status').value=1;")
                                 );            

            }
            else
            { 
                echo " Stored "; 
                echo "</label><label id='action2'>";
                echo $ajax->link('[ Publish ]',
                                    array('controller'=>'articles','action'=>'approve_admin',$data['articles']['id']),
                                    array('update'=>'result','class'=>'sky','complete'=>"document.getElementById('status').value=1;")
                                 );            

            }
            echo " ";
            echo $ajax->link('[ Edit ]',
                                array('controller'=>'articles','action'=>'edit_admin',$data['articles']['id']),
                                array('update'=>'slip','class'=>'sky','complete'=>"make_slip(); document.getElementById('status').value=1;")
                             );            
            echo " ";
            echo $ajax->link( '[ Delete ]', 
                    array('controller' => 'articles', 'action' => 'delete_admin',$data['articles']['id']),
                    array('update' => 'result','class'=>'sky','complete'=>"document.getElementById('status').value=1;"),
                    "Are you sure ?"
                    );                           
            echo "</label>";
            echo "<br style='margin-bottom:2px'>";
        }
    }
    else
    { echo "<span class='red'>Sorry, there is no data in this category</span>"; }
      
?>